<#assign ctx = request.contextPath />
<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
  	<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0"/>
  	<META NAME="ROBOTS" CONTENT="NOINDEX,NOFOLLOW">
  	<title>${Func.getMainCompanyJc()?if_exists}管理系统登陆</title>
	<link href="${ctx}/assets/css/login.css" rel="stylesheet" />
	<link rel="shortcut icon" type="image/x-icon" href="${ctx}/assets/img/ezu.png" />
	<style type="text/css">
		.ezu-bottom {
			margin-top: 150px;
			text-align: center;
		}
	</style>
</head>

<body onkeydown="on_return();">
	<div class="nav" id="u_p_login">
		<div class="nav-title">
			<h1>${Func.getMainCompanyJc()?if_exists}</h1>
		</div>
		<form id="login_form" action="${ctx}/login" method="post" autocomplete="off">
			<div id="usps_div">
				<div class="nav-text">
					<img src="${ctx}/assets/img/login-two-tb.png" style="float: left;"/>
					<input  class="thick" type="text"  id="username" name="username" placeholder="用户名" autocomplete="off" maxlength="30" required/>
				</div>
				<div class="nav-text-mima">
					<img src="${ctx}/assets/img/login-two-mima.png"  style="float: left;"/>
					<input  class="thick" type="password" id="password" name="password" placeholder="密码" autocomplete="off" maxlength="50" required/>
				</div>
				<div class="nav-verification">
					<img src="${ctx}/assets/img/login-two-vt.png" style="float: left; margin-top: 10px; "/>
					<input class="thick" type="text" id="captcha_input" name="captcha" placeholder="验证码" style="margin-top: 5px; margin-bottom: 5px;" maxlength="4" required />
					<img id="captcha" src="${ctx}/captcha" style="float:right;margin-top: -19px;width: 130px; height: 57px;" />
				</div>
				<a id="login_button" class="button-a" href="javascript:;">
					<div class="button">
						<h2>登录</h2>
					</div>
				</a>
			</div>
			<div id="vcode_div" style="display:none;">
				<div id="vcode_msg_div">
					
				</div>
				<div class="nav-text">
					<img src="${ctx}/assets/img/login-two-mima.png"  style="float: left;"/>
					<input  class="thick" type="text"  id="vcode" name="vcode" placeholder="校验码" autocomplete="off" required/>
				</div>
				<a id="login_vcode_button" class="button-a" href="javascript:;">
					<div class="button">
						<h2>登录</h2>
					</div>
				</a>
			</div>
			<div id="error_message" class="button-text"></div>
		</form>

    </div>
	<div class="ezu-bottom">
		<img src="${ctx}/assets/img/online.png" width="18">
		<img src="${ctx}/assets/img/second.png" width="18">
		<span style="font-size: 13px;">
			蜀ICP备19014924号-1
		</span>
	</div>
</body>

<script src="${ctx}/assets/js/jquery-1.11.0.min.js"></script>
<script src="${ctx}/assets/js/md5.js"></script>
<script src="${ctx}/assets/js/base64.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function(){
	<#if shiroLoginFailure??>
		<#if shiroLoginFailure == "org.apache.shiro.authc.pam.UnsupportedTokenException">
			$("#error_message").html("验证码错误");
		<#elseif shiroLoginFailure == "org.apache.shiro.authc.UnknownAccountException">
			$("#error_message").html("用户名或密码错误");
		<#elseif shiroLoginFailure == "org.apache.shiro.authc.IncorrectCredentialsException">
			$("#error_message").html("用户名或密码错误");
		<#elseif shiroLoginFailure == "org.apache.shiro.authc.DisabledAccountException">
			$("#error_message").html("该账号已被锁定");
		<#elseif shiroLoginFailure == "com.ybkj.daijia.server.exception.LoginVcodeErrorException">
			$("#error_message").html("校验码错误");
		<#elseif shiroLoginFailure == "com.ybkj.daijia.server.exception.DebtsErrorException">
			window.location="${ctx}/debts";
		</#if>
	</#if>
	
	$("#captcha").click(function(){
		$(this).prop('src','${ctx}/captcha?t=' + new Date().getTime());
	});
	
	var num=GetRandomBg(1,3);
	$("body").attr("background","${ctx}/assets/img/bj-"+num+".jpg");
	
	//resize();
	
	//$(window).bind('resize',resize);
	
	$("#login_button").click(function(){
		if($("#username").val()==""){
			$("#error_message").html("请输入用户名");
			return;
		}
		if($("#password").val()==""){
			$("#error_message").html("请输入密码");
			return;
		}
		if($("input[name=captcha]").val()==""){
			$("#error_message").html("请输入验证码");
			return;
		}
		$.post("${ctx}/checkusps",
		{"username":$("#username").val(),"password":new Base64().encode($.md5($("#password").val())),"captcha":$("#captcha_input").val()},
		function(result){
			if(result.success){
				if(result.result=="Login"){
					$("#password").val(new Base64().encode($.md5($("#password").val())));
					$("#login_form").submit();
				}
				else if(result.result=="startPhoneLogin"){
					$("#usps_div").hide();
					$("#vcode_div").show();
					$("#vcode_msg_div").html("已发送短信至尾号"+result.phone+"的手机，请填写短信校验码");
					$("#error_message").html("");
				}
			}
			else{
				$("#captcha").click();
				if(result.result=="UnknownAccount"){
					$("#error_message").html("请输入正确的用户名、密码、验证码");
					return;
				}
				else if(result.result=="UnsupportedTokenException"){
					$("#error_message").html("验证码错误");
					return;
				}
				else if(result.result=="DisabledAccount"){
					$("#error_message").html("该用户已被禁用");
					return;
				}
				else if(result.result=="IncorrectCredentials"){
					$("#error_message").html("用户名或密码错误");
					return;
				}
				else if(result.result=="AccountPhoneNull"){
					$("#error_message").html("该用户未设置手机号码，无法发送登录验证码");
					return;
				}
			}
		});
	});
	
	$("#login_vcode_button").click(function(){
		if($("#vcode").val()==""){
			$("#error_message").html("请输校验码");
			return;
		}
		$.post("${ctx}/checkvcode",$("#login_form").serialize(),function(result){
			if(result.success){
				$("#password").val(new Base64().encode($.md5($("#password").val())));
				$("#login_form").submit();
			}
			else{
				if(result.result=="vcodewrong"){
					$("#error_message").html("校验码错误");
					return;
				}
				else if(result.result=="vcodeinvalid"){
					$("#error_message").html("校验码已失效，请重新登录获取");
					return;
				}
			}
		});
		
	});
	
});

function on_return(){
	if(window.event.keyCode == 13){
		if($("#usps_div").is(":hidden")){
			$("#login_vcode_button").click();
		}
		else if($("#vcode_div").is(":hidden")){
			$("#login_button").click();
		}
	}
}
 
function resize(){
	//var height=document.documentElement.clientHeight;
	//$("#wrapper").css("height",height);
	//$(".login_box").css("margin-top",(height/2)-297);
}

function GetRandomBg(Min,Max){   
	var Range = Max - Min;   
	var Rand = Math.random();   
	return(Min + Math.round(Rand * Range));   
}   
	
</script>

</html>